/**
 * 订单相关 WebSocket 事件处理器
 */
const handleOrderCreated = (io, socket) => {
  socket.on('server:order-created', async ({ orderId, message }) => {
    console.log(`[WebSocket] 发送订单创建通知，订单ID=${orderId}`);
    io.to(socket.id).emit('client:order-created', { orderId, message });
  });
};

const handleOrderPaid = (io, socket) => {
  socket.on('server:order-paid', async ({ orderId, message }) => {
    console.log(`[WebSocket] 发送订单支付成功通知，订单ID=${orderId}`);
    io.to(socket.id).emit('client:order-paid', { orderId, message });
  });
};

const handleOrderCanceled = (io, socket) => {
  socket.on('server:order-canceled', async ({ orderId, message }) => {
    console.log(`[WebSocket] 发送订单取消通知，订单ID=${orderId}`);
    io.to(socket.id).emit('client:order-canceled', { orderId, message });
  });
};

module.exports = {
  handleOrderCreated,
  handleOrderPaid,
  handleOrderCanceled,
};